<template>
	<view class="content padd20">
		<u-search placeholder="搜索课程" v-model="keyword" @click="search" :animation="true"></u-search>
		<view class="mt20">
			<view class="course" v-if="list.length > 0">
				<view class="course-list box box-align-center padd20 mb20" v-for="(item,index) in list" :key="index"
					@click="goDetail(item)">
					<u-image width="240rpx" height="180rpx" :src="item.image"></u-image>
					<view class="ml10 box box-tb">
						<h3 style="font-weight: bold;font-size: 32rpx;">{{item.name}}</h3>
						<view class="" style="color: #ABB0C4;font-size: 24rpx;">
							共{{item.stageCnt}}章
						</view>
						<view class="mt20 times">
							<u-icon name="eye" color="#181623 " size="32" class="mr10"></u-icon>
							{{item.clickCnt}}
						</view>
					</view>
				</view>
			</view>
			<view class="" v-else>
				<noData title="暂无课程"></noData>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				list: []
			}
		},
		onLoad() {
			this.getCourseList()
		},
		methods: {
			search(e) {
				console.log(e);
				this.getCourseList()
			},
			getCourseList() {
				let opt = {
					url: "/ycouspublic/list"
				}
				let params = {
					cousname: this.keyword
				}
				this.$api.post(opt, params,true).then(res => {
					console.log(res);
					if (res.code == 0) {
						this.list = res.list
					}
				})
			},
			goDetail(item) {
				uni.setStorageSync("course-info",JSON.stringify(item))
				uni.navigateTo({
					url: "/Public/CourseDetail/CourseDetail?id="+item.id
				})
			},
			//课程查看次数+1
			addCnt(item) {
				let opt = {
					url: "ycouspublic/click"
				}
				let params = {
					cousid: item.id
				}
				this.$api.post(opt, params).then(res => {
					console.log(res);
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		box-sizing: border-box;
		background: #F6F9FF;
	}

	.course {

		// height: 563rpx;
		// background: #FFFFFF;
		// box-shadow: 0rpx 9rpx 46rpx 0rpx rgba(187, 205, 223, 0.14);
		// border-radius: 23rpx;
		.course-list {
			background: #FFFFFF;
			box-shadow: 0rpx 9rpx 46rpx 0rpx rgba(187, 205, 223, 0.14);
			border-radius: 23rpx;

		}

		.times {
			padding: 6rpx 10rpx;
			background: #F6FAFF;
			border-radius: 44rpx;
			font-size: 20rpx;
		}
	}
</style>
